<style>
    .dhh-push-list-tab {
        height: 789px;
        margin-top: 10px;
        float: left;
        width: 100%;
    }
    
    .click-opraty {
        font-size: 20px;
        cursor: pointer;
        margin: 5px;
    }
    
    #show-distributors {
        float: left;
        padding: 15px;
        width: 100%;
        height: 100%;
    }
</style>
<div id="dhh-push-list" class="show_page_content">
    <!-- 顶部按钮 -->
    <div class="dhh-push-list-tab">
        <table id="dhh-push-list-table"></table>
    </div>
</div>
<script>
    layui.use(["table"], function() {
        var laytab = layui.table;
        //laydate 时间控件
        var heigth = $("#page-container").height() - 30;
        $(".dhh-push-list-tab").height(heigth);
        //搜索
        $("#hometotal-search").on("click", function() {
            laytab.reload('usertable');
        });

        renderTable();

        $("#dhh-push-list").on("click", ".edit", function() {
            var id = $(this).attr("uid");
            var index = layer.confirm("<span style='color:indianred'>" + titles + "</span>", {
                icon: 0
            }, function() {
                $.ajax({
                    url: "/msg/msg_send",
                    type: "post",
                    data: {
                        id: id
                    },
                    dataType: "json",
                    beforeSend: function() {
                        loadIndex = layer.load(0);
                    },
                    success: function(d) {
                        layer.close(loadIndex);
                        layer.close(index);
                        if (d.result == "1") {
                            layer.msg("推送成功！", {
                                icon: 1,
                                time: 2000
                            });
                            if (fn) {
                                laytab.reload('usertable', {
                                    where: {
                                        title: $("#app_name").val(),
                                    }
                                });
                            }
                        } else {
                            layer.msg(titles + "推送失败！", {
                                icon: 2,
                                time: 2000
                            });
                        }
                    },
                    error: function() {
                        layer.close(loadIndex);
                        layer.close(index);
                        layer.msg("网络异常！", {
                            icon: 2,
                            time: 2000
                        });
                    }
                });
            });
        });
        delRow("#dhh-push-list .del", "/msg/msg_del", function() {
            laytab.reload('usertable', {
                where: {
                    title: $("#app_name").val(),
                }
            });
        });

        function renderTable() {
            laytab.render({
                elem: '#dhh-push-list-table',
                height: heigth,
                url: "/msg/msg_list",
                method: "get",
                id: "usertable",
                response: {
                    statusName: "result",
                    msgName: 'tips' //规定状态信息的字段名称，默认：msg
                        ,
                    countName: 'total' //规定数据总数的字段名称，默认：count
                        ,
                    dataName: 'rows',
                    statusCode: 1 //规定成功的状态码，默认：0
                },
                request: {
                    pageName: 'page' //页码的参数名称，默认：page
                        ,
                    limitName: 'lines' //每页数据量的参数名，默认：limit
                },
                done: function(d) {
                    $(".layui-none").text(d.tips);
                },
                parseData: function(res) { //res 即为原始返回的数据
                    return {
                        "result": res.result, //解析接口状态
                        "tips": res.tips, //解析提示文本
                        "total": res.total, //解析数据长度
                        "rows": res.rows //解析数据列表
                    }
                },
                cols: [
                    [{
                        title: "ID",
                        field: "id"
                    }, {
                        title: "推送信息",
                        field: "content"
                    }, {
                        title: "是否已推送",
                        field: "is_jpush"
                    }, {
                        title: "推送时间",
                        field: "jpushtime"
                    }, {
                        title: "提交时间",
                        field: "posttime"
                    }, {
                        title: "操作管理",
                        unresize: true,
                        width: "10%",
                        templet: function(d) {
                            return "<a class='click-opraty' title='点击推送'><i class='layui-icon layui-icon-release edit' uid='" + d.id + "' style='color:#393D49;'></i></a>" +
                                "<a class='click-opraty' title='点击删除'><i class='layui-icon layui-icon-delete del' uid='" + d.id + "' style='color:#393D49;'></i></a>";


                        }
                    }]
                ],
                page: true,
                limits: [20, 50, 100],
                limit: 20,
                loading: true,
                skin: {
                    even: true
                },
            });
        }
        //点击查看
        $("#dhh-push-list").on("click", ".show", function(ev) {
            var indexVal = $(ev.target).parent().attr("index");
            var loadindex = null;
            layer.open({
                type: 1,
                shade: 0.6,
                btn: false,
                title: "查看渠道列表",
                area: [$(document).width() * 0.9 + "px", $(document).height() * 0.9 + "px"],
                content: "<table id='show-distributors' style='display:none;'></table>",
                success: function(r, index) {
                    laytab.render({
                        elem: '#show-distributors',
                        height: $("#show-distributors").height() - 40,
                        width: $("#show-distributors").width(),
                        url: "/distributors/sub_lists",
                        method: "get",
                        id: "usertables",
                        response: {
                            statusName: "result",
                            msgName: 'tips' //规定状态信息的字段名称，默认：msg
                                ,
                            countName: 'total' //规定数据总数的字段名称，默认：count
                                ,
                            dataName: 'rows',
                            statusCode: 1 //规定成功的状态码，默认：0
                        },
                        request: {
                            pageName: 'page' //页码的参数名称，默认：page
                                ,
                            limitName: 'lines' //每页数据量的参数名，默认：limit
                        },
                        done: function(d) {
                            $(".layui-none").text(d.tips);
                        },
                        where: {
                            uid: indexVal
                        },
                        parseData: function(res) { //res 即为原始返回的数据
                            return {
                                "result": res.result, //解析接口状态
                                "tips": res.tips, //解析提示文本
                                "total": res.total, //解析数据长度
                                "rows": res.rows //解析数据列表
                            }
                        },
                        cols: [
                            [{
                                title: "序号",
                                field: "uid",
                                unresize: true,
                            }, {
                                title: "用户名",
                                field: "username",
                                unresize: true,
                            }, {
                                title: "所属角色",
                                field: "mid",
                                unresize: true,
                                unresize: true,
                                templet: function(d) {
                                    if (d.mid == 0) {
                                        return "管理员";
                                    } else if (d.mid == 1) {
                                        return "一级渠道商";
                                    } else if (d.mid == 2) {
                                        return "二级渠道商";
                                    }
                                }
                            }, {
                                title: "注册时间",
                                field: "adddate",
                                unresize: true,
                            }, {
                                title: "H5链接",
                                field: "h5_link",
                                unresize: true,
                            }, {
                                title: "APP链接",
                                field: "app_link",
                                unresize: true,
                            }, {
                                title: "token查询链接",
                                field: "token_link",
                                unresize: true,
                            }]
                        ],
                        page: true,
                        limits: [20, 50, 100],
                        limit: 20,
                        loading: true,
                        skin: {
                            even: true
                        },
                    });

                }
            })
        });
        //点击删除
    });
</script>